﻿@*
    表单内容
*@

@using NewLife;
@using XCode;
@using XCode.Configuration;
@using NewLife.Cube;
@using NewLife.Cube.ViewModels;
@{
    var entity = Model as IEntity;
    var isNew = entity.IsNullKey;
    var fields = ViewBag.Fields as FieldCollection;
    var groupFields = fields.GroupByCategory(entity);

    var set = NewLife.Cube.CubeSetting.Current;
    var cls = set.FormGroupClass;
    if (cls.IsNullOrEmpty())
    {
        cls = "col-xs-12 col-sm-6 col-lg-6 pt-2";
    }
}

<div class="card-body">

    @await Html.PartialAsync("_Form_Body_Message")

    @if (groupFields.Count > 1)
    {
        var i = 0;
        <div class="tab-content">
            @foreach (var group in groupFields)
            {
                <div class="tab-pane fade @(i == 0 ? "active show" : "")" id="@("form_tab"+i)">
                    <div class="row">
                        @foreach (var item in group.Value)
                        {
                            var des = item.Description.TrimStart(item.DisplayName).TrimStart(",", ".", "，", "。");
                            var dataField = fields.GetField(item.Name) as ListField;
                            var display = dataField?.DisplayName ?? item.DisplayName;

                            if (item.Name.EqualIgnoreCase("permission"))
                            {
                                @await Html.PartialAsync("_Form_SetPermission", new { Role = entity })
                            }
                            else if (item.IsBigText())
                            {
                                <div class="">
                                    <!-- 字段标签（含帮助说明信息） -->
                                    <div class="d-inline-flex align-items-center">
                                        <label class="col-form-label me-2" for="@item.Name">@display</label>
                                        @if (!des.IsNullOrEmpty())
                                        {
                                            <div class="d-none d-md-block d-lg-block">
                                                <i class="fas la-question-circle" data-bs-toggle="tooltip" title="@des"></i>
                                            </div>
                                        }
                                    </div>

                                    <!-- 字段编辑框 -->
                                    <div class="flex-grow-1">
                                        @await Html.PartialAsync("_Form_Editor", new ValueTuple<IEntity, DataField>(entity, item))
                                    </div>
                                    <span class="form-text text-muted d-sm-none"><span class="form-text text-muted">@des</span></span>
                                </div>
                            }
                            else
                            {
                                var hide = item.Name.EqualIgnoreCase("ID") ? "d-none" : "";
                                <div class="@cls @hide">
                                    <!-- 字段标签（含帮助说明信息） -->
                                    <div class="d-inline-flex align-items-center">
                                        <label class="col-form-label me-2" for="@item.Name">@display</label>
                                        @if (!des.IsNullOrEmpty())
                                        {
                                            <div class="d-none d-md-block d-lg-block">
                                                <i class="fas la-question-circle" data-bs-toggle="tooltip" title="@des"></i>
                                            </div>
                                        }
                                    </div>

                                    <!-- 字段编辑框 -->
                                    <div class="flex-grow-1">
                                        @await Html.PartialAsync("_Form_Editor", new ValueTuple<IEntity, DataField>(entity, item))
                                    </div>
                                    <span class="form-text text-muted d-sm-none"><span class="form-text text-muted">@des</span></span>
                                </div>
                            }
                        }
                    </div>
                </div>
                i++;
            }
        </div>
    }
</div>

